Okay, so last lecture we started off scripting during the major scripts for our hobby.
Um, we did the um we did we did the spawn locations, which works quite nicely.
And now we're just looking at this label up here.
So let's just pick up off where we looked at last time.
We had it working so that it will change the stage label when you go on each start part, and we're
just going to have a look, um, the next bit will have the code will be the end part.
So, um, we will do.
Stage dot.
End dot touched.
Connect function hit okay.
And when this happens well we'll want to update.
Um.
Yeah, we can set it to be the same thing.
Oh, no.
We need to do our check first.
We can just copy and paste this actually be there.
Um, when we end.
There's no harm in setting this to be the thing.
I guess if you're trying to, like, go backwards or something, just to make keeping everything consistent.
Um.
And, um.
Yeah.
So, um.
It.
That should be it on the label side.
Now we can have a look at the actual timer.
So the timer itself I'm going to separate into functions just so it's a bit easier really.
Um, if we incorporate into the actual code.
A timer isn't advanced code, but it's just very lots of formatting and stuff to do.
So a bit of a pain.
To be honest.
I wish there was some built in feature which allows you to make a timer, but there's not.
Um, but yeah.
So I'm going to make one function called start timer.
And one function called end timer.
And then Firebase functions inside here.
So when you touch the start I'm going to start the timer.
Part timer.
And in here we get end of the timer like that there.
Cool.
So, um.
The timer.
Okay, so have a think for a minute.
How might we do this?
Timer?
One fort.
Let's just make a repeat until false.
Um, seconds is equal to seconds.
Seconds is equal to seconds plus one.
And then format VAT or uh, but not quite because that works fine till we get to nine seconds.
Um, sorry.
Works for one.
We get 1550 nine seconds but won't get to 60.
It then goes 60, 61, 62, 63 and really wanted to display minutes as well.
It wouldn't look as nice if it was just seconds taking up now.
I mean, if if your stage is if it's taking you more than a minute to do one of these stages apart from
like that first one maybe, um, there's a little bit embarrassing.
Um, but I wanted to show you this in case you have longer stages or anything like that, and it's good
to just prepare for it if it does happen.
So that's not what we're going to do here.
Um, we're going to define two variables.
One called minutes.
And set that equal to zero.
And one called seconds is equal to zero.
We are going to be we're going to do it similar though.
We're going to make a repeat until um.
Oh, no.
Okay, so we can't use a repeat until false because basically that would mean whenever we start the
timer.
Um, it would be an infinite loop and never exit.
So basically, as soon as you start it, you can't exit it or do anything else.
The code will basically be stuck here, which you don't want.
Um, if we make a yeah, yeah, if we make a variable called in stage.
Is equal to false, and just track to see when the player is or isn't in a stage.
So for example, when they click, when they touch the start part, they are then in a stage.
So in stage is equal to true.
And here.
In stages, obviously equal to false.
So if they're currently in the stage and what we can do is we can, um, set this up here to be until
not in stage.
So this timer will repeat until no longer in a stage where it will stop, which is exactly what we want.
Okay, so, um.
We were right.
Seconds is equal to seconds plus one.
Nice and simple.
Um, however, when once it reaches 60s, I want it to instead be one minute.
So basically we're going to check to see, um, if seconds is equal to 60.
We are going to set the minutes to equal the minutes plus one.
So we're adding a minute on every time seconds is equal to 60.
And then setting seconds to equal to zero.
So 60s then becomes one minute and zero seconds.
Um, really obvious stuff really.
But remember the code script doesn't know that.
So you have to tell it all that information.
Okay.
So this is where, um, we have to do a bit of something called concatenation, which for someone learning
probably sounds really complex.
Um, when you concatenate something, but it's simple as just, um, attaching two strings together
or like a string and a number, or just attaching something to a string, it's called concatenating
it.
Um, and we do this because we want, um, the minutes to show here and then a colon to show and then
the seconds to show.
And we are doing it is concatenating it.
So we have the minutes a colon and then a seconds.
So we can do this by setting the timer label dot text value to be equal to the minutes.
And concatenate is actually really simple.
It's just two dots like that which joins it together to your next element, which is our colon there,
and then join it again to our second.
You can join as many things you want to concatenate in it.
Um, okay.
So um, let's see what this will look like.
Spoiler alert it's not going to look very good.
Um works in some function, but not 100%.
So if we start a stage.
Oh.
It's happening here.
It's completely frozen for me.
Whoa.
Okay, now was not.
Whoa!
Okay.
Interesting time.
Um.
What terrible thing did I do wrong?
Um.
Oh, no, I didn't put a weight.
In my repeating tool.
False.
I'm supposed to be the teacher here, and that is a terrible mistake to make.
We all make it, though.
It's fine.
Um, let's give that another go.
Cool.
So this is what happens when you did a simple concatenation like I did there.
Um, doesn't look very pretty once you get to that part time look, it looks all right.
Um, I'm not going to bore you and wait for a minute to show you, but, um, yeah, basically a couple
of issues of it.
The main issue being if it's less than nine, we want to still show the first zero.
Um, and we do that with doing a bunch of different if statements.
Um, so.
If and b minutes is bigger than nine and the seconds is bigger than nine, then that means that they
both take up two digits, so we don't have to include any extra zeros, so we can just do it as we did
before.
Timer label dot text is equal to minutes dot dot colon dot dot seconds.
Okay let's create an else if here.
But let's suppose um seconds is less than nine for example.
So we can do this by just we can just check if minutes is is bigger than nine.
And this would mean that seconds isn't because if it was this would run here.
Um, in this case, we need to put a zero in front of seconds.
So timer label.
Um, sorry.
Timer label dot text is equal to minutes dot dot a and colon and then a zero.
Dot dot seconds.
Cool.
Another else if if it's the other way around.
So seconds is bigger than nine.
Then we want to do our timer label.
Dot text is equal to um um at the front.
So zero.
Dot dot minutes.
Dot dot.
Colon.
Dot.
Seconds.
And then the last case scenario is that they're both less than nine.
This is where it gets really tedious.
Um timer label dot text is equal to zero.
Dot dot.
Minutes.
Dot dot.
Colon 0.. seconds.
Okay, now all this might look a bit confusing, but basically you just put it as this is getting added
in front of our minutes, which then we have our colon and our number zero.
It's just formatting.
So everything looks nice and clean.
Now.
If I give it a go, it will look miles better and actually like a proper timer that we would expect.
Happened there.
Um, let's give it another go.
Not too sure why that happened.
Okay.
Oh, I've got another error going on here.
It's completely frozen again.
Oh, what have I done?
What?
I thought I fixed that issue.
Am I being stupid?
Okay.
Just give it a minute.
Basically what happens when you don't include a weight in your repeat loop?
Um, it doesn't like it.
Um.
It's timed out, so I'm not sure why it's still frozen.
There we go.
Okay.
Um, that is a very long time.
Um, okay.
I thought I included a weight.
That's so strange.
Okay.
Um, I thought included a weight, obviously I didn't, so, um.
That's weird, but, um.
Okay, let's give that a go.
Okay.
Nice.
So you can see here we've got a nice timer ticking up like that and it looks nice and clean.
Um, no sudden jumps when it gets to 9 to 10 or anything.
It just all flows nicely.
So with a simple timer like this, there's a lot of formatting and stuff that you wouldn't originally
have thought, which is quite interesting.
Um, but yeah.
Um, yeah.
Again, I'm not going to show up to a minute.
Feel free.
But if you want to check.
Um, up to a minute.
Um, what happens after 59 minutes?
However, it just takes up to 60 minutes.
61 minutes, 62 minutes.
Um, you could add the extra functionality, um, so that you'd have hours showing, but nobody in their
right mind is going to take an hour on a stage, um, in one life as well.
So there wouldn't really be much point on doing that.
Um, cool.
So, um.
I think that's pretty much fair, to be honest.
Let's give that a let's give that a go and see any other additions we need to make.
Oh, no.
Sorry.
Um, end the timer.
I've just remembered we haven't done his end timer function yet, so this would be nice and simple,
actually, um.
All will need to do here is.
Set the, um.
Um, well, if we.
Hang on.
Yeah.
Take this out.
Put this in our end timer function in stage is equal to false.
And then also set the actual value of the timer timer label dot text to equal the default zero zero
colon zero zero.
So it starts at the end.
And that's probably all that we need.
So let's give this a go.
Okay, so stage one.
Let's give this a go.
Okay.
The timer started.
It's been cool.
So you can like try out and see how fast you can do.
Do it.
Okay, let's see how I'm going to go over it.
It now switches the timer.
Um, and then I'm still counting on stage one, but when I go to stage two, it shows where stage two.
And, um.
Yeah, I'm just testing out.
Just testing it out.
You do still die.
Of course.
Um.
Okay.
Never mind.
Uh, okay.
Um, yeah, that all works nicely.
Only thing I think is that once you pass the end, you should be on the next stage.
Um, is there any way we can do that?
Stage label.
Text.
Um.
What if we set this to, like, um.
Stage complete.
Let's see what that might look like, because I don't want it to stay.
Stage one when you finished stage one.
Stage complete.
Day two, I like that.
Cool.
Um, nice.
Well, that is that system coded, um, or.
Well, which I'm happy about.
Cool.
So.
Yeah.
There we go.
We've got a nice timer displaying there, and, um.
Yeah, it feels more like an obby.
Now we've got a bit more, um, a bit of, like, intelligence, I guess, um, into it, but, um.
Yeah.
Cool.
So this is where I'd wanted to do a couple other things.
Really, before we finish off, um, well, before we completely finish this, um, hobby.
Really?
Um, first thing, as you notice, there's a, um, error coming up here.
Thank you.
Letter.
Um, because the person who's made this script, which I believe it's to do with one of these free models
added in over here and decided to.
Put all this in here.
Um, the Twitter and Instagram and stuff.
Um, but did not not to note it at all.
So it it thinks it's actual text.
Um, so yeah, we need to get rid of that.
And there's probably a lot of other scripts as well that are doing really random things that I want
to completely get rid of, basically.
So let's just search up script to see, um, like here.
This is not surprise me at all.
There's all these different scripts doing all these different kinds of things.
Um, that's our script.
This script.
Oh, wow.
Okay.
Um, well, this person didn't take this course because if they did, they would know that, um, this
is not a very efficient or nice way to code at all.
Um, not pleasant to look at all.
What is this for?
A fan.
Okay.
Yeah.
Let's get rid of the fan.
Um, this is just for decoration.
I'm not too bothered.
If not all of it is working properly.
This.
This is all for a fan.
Uh, missed Oprah fan too.
Yeah, I'm not too worried, but it doesn't all, like, completely work.
Like, this is.
This is for, like, um, stuff and that part.
Oh, you probably do want that to be.
To be fair, that's not too bad of a script at all.
Or be.
I'm not going to need these parts, are we?
No.
Is the issue.
Um, we've taken stuff from a toolbox is.
But they sometimes have really weird scripts.
But, I mean, now that you know the basics of scripting, hopefully you can kind of read it and, um,
kind of be able to tell.
Yeah, that's not right.
Let's get rid of that because it just looks terrible.
Um.
I'll keep those two.
And that should be all of the scripts got gotten rid of.
Nice.
So whatever stuff you've added in from a toolbox, make sure doesn't have any scripts, that's kind
of messing things up, I guess.
Um, as you don't want something that contains viruses.
Um, don't get rid of it.
Um.
Ah.
Maybe it didn't show all of the scripts.
Maybe some of them are not called scripts.
In that case, what we can do is just quickly take all this and we can use expand all so we can see.
Yeah.
See, there's still difference.
There's still scripts but weren't we didn't find earlier.
So let's just go through and delete any scripts that we can find because we don't want them unless they're
absolutely essential.
Yeah, there's a lot.
There's a lot of parts here.
Um, yeah.
Delete a few for decoration.
Yes it is.
Cool.
Um.
Just keep scrolling.
Making sure we don't leave anything.
I don't think there are any other scripts now, and.
But you never know.
Oh that's it part.
That's what we do want in that script.
And.
I mean, there's a couple of pilot scripts as well.
Sit pilot script there.
Tire swing.
You do want that?
Swing script.
Want to keep that?
Okay, cool.
That's all of them.
Nice.
So just make sure there's no other scripts interfering with what's going on in our game.
Nice.
Let's play the game again and just make sure there's nothing else outputting as you want a nice clean
output.
So if you are making any other additions to your game, you know that something might not be right.
For example.
And yeah, it's a clean, nice clean output there.
Perfect.
Um, so why don't we have a quick test at our game then?
So play the game.
Let's do a whole run through of the game.
Make sure you always want to play test your game before you call it finish.
So let's have a go at doing that because you never know what errors and stuff might be lurking around.
Now it will help if I'm.
Any somewhat good at this.
Um, takes a long time to reload, which is something we can nice and easily fix.
Okay, cool.
Stage complete.
Stage two.
This one seems to be the stage that keeps.
I'm finding it very difficult to do.
Right.
Stage two.
Oh.
Come on.
Uh.
All right, let's jump over.
I need to jump and then move, but then don't move enough.
Oh, this is annoying me.
And get one more try.
If not, I'm just going to skip it.
Um.
Come on.
Oh.
Come on.
Is it not impulsive?
Is it not possible, then?
I mean, if I'm not able to do it, maybe that's something that we need to just adjust.
I think personally, maybe we should just adjust that a little bit.
Because I don't want it to be too difficult.
There we go.
Because if I give it a couple tries and it's not working, it's going to just make people who are playing
the game annoyed at me, annoyed, annoyed, not annoyed at me, but annoyed at, um, whoever made
it.
Cool, right?
This is embarrassing.
Let's give it another go.
Okay, let's just skip that.
Let's.
If I skip on to stage three.
I just can't manage to do that.
No.
It says.
No, it says stage one.
But it's now stage three here.
I've started the timer, which is a bit annoying, but yes, this is the one with the moving parts.
So let's give this a go.
We jump over onto it.
Nice.
This one's, I think is a little bit tricky, actually.
Oh, what's happening with a timer?
A two timers running at the same time.
I will not be a simple fix, actually, because I, um, went through it, went through, went through
the start part and then went back basically was the issue.
So like here.
And never do it again.
Is going to completely glitch out.
Yeah, that'd be a nice easy fix basically to not let the function run again.
Um, if it's already going and oh, it's supposed to be, it's going to be something there.
Let's have a look.
The link was missing.
Oh, why was that not there?
Anchor it.
Make sure that's anchored.
Um.
You want to make sure it's anchored.
And this one is just for parts there and then to finish.
Cool.
Um, yeah.
Minor change, then to that script.
Quickly run.
Um, we need to add some bounces.
So let's add a.
Local start.
Bounce is equal to is equal to false.
Local and the bounce is equal to false.
And then down here I can check to make sure it's not currently reading.
Making two is because otherwise it might be issues with them both with having one the bounce for two
events, it's good to have separate ones, um, and not end bounce.
You can.
Otherwise you have a start the bounce and not be able to finish it.
Um, yeah.
Wall de bounces.
Start, the balance is equal to true.
Usually we set it to false down here, but actually we're not going to.
We don't want it to be false until we've actually finished that stage this time.
So in here.
And the balance is equal to true.
Then down here start balance is equal to false.
And then end balance is equal to false.
Cool.
Um, that's all looking nice.
Let's just give that another quick go to make sure when there's a couple other tricks I want to make.
And we are pretty much done.
Um, so we're good.
Let's go back on ourselves.
And timer still keeps ticking.
Perfect.
Cool.
Okay, well, that's all the scripts sorted then.
Um, the other kind of tweaks I wanted to make is, first off, the background looks a bit boring,
really.
So if you go to for toolbox and, um, we can find a nice skybox, we start with skybox that's there,
like, typical name.
Really.
So you'll find some nice things in here.
Um.
Don't bother with any of the skyboxes that are just one decal.
You want them to be multiple, so they cover like all six parts of the screen.
Um.
That one looks nice.
Whoa.
So it just kind of adds a lot more of an atmosphere to it.
Um.
Or like this one.
I like that one.
Let's use this one and let's set this.
Is called sky.
Views of all asset orbit or the image asset IDs each because it basically split up into six basically.
And then celestial bodies, whether the sun and stuff showing.
I'm going to take that off.
Cool.
Um.
Ah, yeah.
Respawning when you die and stuff.
So when you currently die, you have to fall a long distance down.
You then have to wait a couple seconds and then you have to respawn.
That's quite annoying each time it happens.
So if you go over two players sent respawn time to zero, so you immediately respawn and then the actual
kill barrier is basically at a certain point where you die.
I want to bring that up a bit higher.
So this bit here fallen parts destroy.
Set this to something like -50 for example, and let's just play the game and see how that would kind
of change that around.
Feel free to tweak these settings and stuff.
You will need to a little bit.
But see, see, you have to fall a lot less.
Um, I think maybe the respawn is set to like one one second.
So at least something happens, like, um.
But, um.
Yeah.
Tonight for a lot less than you die and you respawn here.
Um, force field as well.
Yeah, yeah.
Um, we don't want a force field on our spawn locations.
It's fine for the first stage, but for the rest, like, if you have a if you have a ten second force
field for this, you can just walk past it all.
So make sure we set this.
Um, duration for the force field to be zero.
We don't want any force field.
Some games like shooter games, games, adventure games, most other games really.
You might want to you might want that on.
But from an obby you definitely don't want that on.
And I think that's pretty much it, really.
I mean, we can always keep making small tweaks and stuff to it and spend a whole nother lesson making
tweaks to it.
Um, but it's a basic first.
Not a not is a complete, um, game, but it's a basic what's the word?
I'm looking for a basic type of game to make, um, which are done quite well.
So hopefully you've enjoyed watching through this section of the course, um, wherever you have, um,
been following along or.
Yeah, following along.
Exactly.
Or you've just been kind of, um.
Copying banks along and trying bits out yourself and stuff like that.
How you've used it.
Hope you've enjoyed it.
Um, and we've got a nice kind of finished product here.
I'd recommend you go go through this, make some tweaks yourself.
Change some of the code, see how it changes.
Um, I think get a lot more out of it if you make your own changes, rather than if you just copy exactly
what I've done here.
But, um, if this is your first game, congrats.
You've got your first game here.
Um, which is pretty nice.
Um, so from here on in the course, if you're watching this in order of how I've recorded it, um,
you're going to go on and start learning some more advanced aspects of both the basics building and
also through scripting.
And we'll then make something we'll make another game later on, um, which will be a bit more advanced
when it was more advanced aspects and stuff.
But once again, hope you enjoyed this.
Um, going through this and I will, um, you can join me in the next lecture wherever, whichever section
of the course you go on to next.